package com.gitee.wsl.ext.base

object Bits {
    fun bitPermuteStep(x: Int, m: Int, s: Int): Int {
        val t = (x xor (x ushr s)) and m
        return (t xor (t shl s)) xor x
    }

    fun bitPermuteStep(x: Long, m: Long, s: Int): Long {
        val t = (x xor (x ushr s)) and m
        return (t xor (t shl s)) xor x
    }

    fun bitPermuteStepSimple(x: Int, m: Int, s: Int): Int {
        return ((x and m) shl s) or ((x ushr s) and m)
    }

    fun bitPermuteStepSimple(x: Long, m: Long, s: Int): Long {
        return ((x and m) shl s) or ((x ushr s) and m)
    }
}
